package logic

import (
	"context"
	"house/models"

	"house/house"
	"house/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type CreateHouseImageLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewCreateHouseImageLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CreateHouseImageLogic {
	return &CreateHouseImageLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// 房源图片发布
func (l *CreateHouseImageLogic) CreateHouseImage(in *house.CreateHouseImageReq) (*house.CreateHouseImageResp, error) {
	// todo: 房源图片发布
	var err error
	h := models.HouseImage{
		HouseId: int(in.HouseId),
		Image:   in.Image,
		Title:   in.Title,
	}
	err = h.Creates()
	if err != nil {
		logx.Error("房源图片添加失败")
		return nil, err
	}
	return &house.CreateHouseImageResp{
		Id: int64(h.ID),
	}, nil
}
